package priv.pront.code.mati.province;

import java.util.*;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-17 12:24
 */
public class MC0212_旅行 {

    static int n;
    static int[] da, ba;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        while (n-- > 0) {
            int N = scanner.nextInt();
            da = new int[N + 1];
            ba  = new int[N + 1];
            int b = 0, d = 0 ,a = 0;
            int M = scanner.nextInt();
            if(N == 1 && M == 0){
                System.out.println("YES");
                continue;
            }
            for (int i = 0; i < M; i++) {
                int u = scanner.nextInt();
                int v = scanner.nextInt();
                da[u]++; ba[v]++;
            }
            for (int i = 1; i <= N; i++) {
                if(ba[i] == 1 && da[i] == 1) a++;
                if(ba[i] == 0 && da[i] == 1) b++;
                if(ba[i] == 1 && da[i] == 0) d++;
            }
            if(b == 1 && d == 1 && a == N - 2){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }

}
